interface String {
    format(...args: any[]): string;
}


String.prototype.format = function (...args: any[]) {
    if (args.length == 0) {
        return this;
    }
    let self = this;
    for (let i = 0; i < args.length; i++) {
        const sval = args[i];
        while (true) {
            let result = null;
            if (typeof (sval) === "number") {
                result = self.match(/(%d)|(%s)/);
                if (result) {
                    self = self.replace(/(%d)|(%s)/, sval.toString());
                    break;
                }
            }
            result = self.match(/%s/);
            if (result) {
                self = self.replace(/%s/, sval);
            }
            else {
                self += "    " + sval;
            }
            break;
        }
    };
    return self;
}


function extend<T, U>(first: T, second: U): T & U {
    let result = <T & U>{};
    for (let id in first) {
        (<any>result)[id] = (<any>first)[id];
    }
    for (let id in second) {
        if (!result.hasOwnProperty(id)) {
            (<any>result)[id] = (<any>second)[id];
        }
    }
    return result;
}

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r != null) {
          return decodeURIComponent(r[2]);
    }
    return '';
}

window["getQueryString"] = getQueryString